import { Button } from 'antd';
import React, { Component } from 'react';
import './GoodsList.css'
import  {connect} from 'react-redux'
import {getGoodsList,addGoodsToCart} from '../../redux/actions/goodsActions'

class GoodsList extends Component {
    constructor(props){
        super(props)
    }

    render() {
        // const List = [{
        //     name:"手机",
        //     price:10000,
        //     number:80,
        //     id:1
        // },{
        //     name:"电脑",
        //     price:8999,
        //     number:30,
        //     id:2
        // },{
        //     name:"平板",
        //     price:4999,
        //     number:8,
        //     id:3
        // }]
        // console.log('',this.props)
        // console.log(getGoodsList())
        const List = this.props.List
        return (
            <div>
                {
                   List.map(item=>{
                       return(
                        <div className='item' key={item.id}>
                            <div>{item.name}</div>
                            <div>价格：{item.price}</div>
                            <div>数量{item.number}</div>
                            <Button onClick={()=>
                               this.props.addGoodsToCart(item.id)
                            } disabled={ item.number ==0}>+</Button>
                        </div>
                       )
                   }) 
                }
   
            </div>
        );
    }
}
export default connect(state=>({List:state.goodsReducers}),{
    getGoodsList,
    addGoodsToCart
}) (GoodsList);